a,b=input().split()
a=int(a)+1
while 1:
n=str(a)
k=""
for i in n:
if i=='4' or i=='7':
k+=i
if k==b:
print(a)
break
a+=1
// Problem: B. Lucky Mask
// Contest: Codeforces - Codeforces Round #104 (Div. 2)
// URL: https://codeforces.com/contest/146/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
/*
Author: MikiMiku
Observation:
Idea:
*/
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define endl '\n'
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define LSB(S) (S & (-S))
#define setAll(S, n) (S = (1 << n) - 1)
#define modulo(S, N) ((S) & (N - 1)) // returns S % N, where N is a power of 2
#define isPowerOfTwo(S) (!(S & (S - 1)))
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
#define turnOffLastBit(S) ((S) & (S - 1))
#define turnOnLastZero(S) ((S) | (S + 1))
#define turnOffLastConsecutiveBits(S) ((S) & (S + 1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S - 1))
typedef complex<double> point;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const int MAX_N = 1e5 + 5;
const ll MOD = 1e9 + 7;
const int FMOD = 998244353;
const ll INF = 1e9;
const ld EPS = 1e-9;
const double PI=acos(-1);
#define fi first
#define se second
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef map<int,int> mii;
//FLOAT PRECISION SETTINGS
/*
cout.setf(ios::fixed,ios::floatfield);
cout.precision(3);
*/
//FILE IO
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
//........................................................................
int mask(int m) {
string s = to_string(m);
//cerr << s << endl;
string res;
for(auto c : s) {
if(c == '4' || c == '7') res += c;
}
//cerr << res << endl << endl;
int ms = (sza(res) == 0 ? -1 : stoi(res));
return ms;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(nullptr); cout.tie(nullptr);
int a, b;
cin >> a >> b;
int ans = 1e9;
for(int i = a + 1; i <= 180000; ++i) {
int m = mask(i);
if(m == b) {
cout << i << endl;
return 0;
}
}
return 0;
}
25A - IQ test | 785A - Anton and Polyhedrons |
1542B - Plus and Multiply | 306A - Candies |
1651C - Fault-tolerant Network | 870A - Search for Pretty Integers |
1174A - Ehab Fails to Be Thanos | 1169A - Circle Metro |
780C - Andryusha and Colored Balloons | 1153A - Serval and Bus |
1487C - Minimum Ties | 1136A - Nastya Is Reading a Book |
1353B - Two Arrays And Swaps | 1490E - Accidental Victory |
1335A - Candies and Two Sisters | 96B - Lucky Numbers (easy) |
1151B - Dima and a Bad XOR | 1435B - A New Technique |
1633A - Div 7 | 268A - Games |
1062B - Math | 1294C - Product of Three Numbers |
749A - Bachgold Problem | 1486B - Eastern Exhibition |
1363A - Odd Selection | 131B - Opposites Attract |
490C - Hacking Cypher | 158B - Taxi |
41C - Email address | 1373D - Maximum Sum on Even Positions |